package supermarket;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import javax.xml.transform.dom.DOMSource;

import net.sf.saxon.Configuration;
import net.sf.saxon.dom.DocumentWrapper;
import net.sf.saxon.om.Item;
import net.sf.saxon.om.NodeInfo;
import net.sf.saxon.query.DynamicQueryContext;
import net.sf.saxon.query.StaticQueryContext;
import net.sf.saxon.query.XQueryExpression;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.tree.tiny.TinyNodeImpl;

import org.w3c.dom.Document;
import org.w3c.tidy.Tidy;



public class Parser {
	public Parser(){
		
	}
//	public static void main(String[] args) throws IOException, XPathException {
//		//indicate url
////		String urlString = "http://finance.yahoo.com/q?s=IBM";
//		String urlString = "http://www.delhaizedirect.be/ProductList.aspx?cid=W07001003001";
//
//	    URL url = new URL(urlString);
//	    InputStream in = url.openStream();
////	    InputStreamReader r = new InputStreamReader(in, encoding);
//	    
//	    //transform html to dom
//		Tidy tidy = new Tidy(); 
//		tidy.setQuiet(true);
//		tidy.setShowWarnings(false);
//		Document tidyDOM = tidy.parseDOM(in, null);
////		System.out.println(tidyDOM);
//		
//		//parse dom tree
//		File queryFile = new File("query.txt");
////		String query = "";
//		Reader reader = new FileReader(queryFile);
//		Configuration c = new Configuration();
//
//		StaticQueryContext qp = c.newStaticQueryContext();
//		XQueryExpression xe = qp.compileQuery(reader);
//		DynamicQueryContext dqc = new DynamicQueryContext(c);
//		dqc.setContextItem(new DocumentWrapper(tidyDOM, urlString, c));
////		dqc.setContextItem(c.buildDocument(new DOMSource(tidyDOM)));
//
//		List result = xe.evaluate(dqc);
////		Object result = xe.evaluateSingle(dqc);
//		System.out.println(result.size());
//		for(int i = 0; i < result.size(); i++){
//			System.out.println(result.get(i));
//		}
//	}

}
